home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / gnome-applets / invest-applet < prev    next >
Encoding:
Text File  |  2009-04-23  |  2.4 KB  |  100 lines

  1. #!/usr/bin/env python
  2. #
  3.  
  4. import gobject
  5. import gtk, gnomeapplet
  6.  
  7. import getopt, sys
  8. from os.path import *
  9.  
  10. # Allow to use uninstalled
  11. def _check(path):
  12.     return exists(path) and isdir(path) and isfile(path+"/ChangeLog")
  13.  
  14. name = join(dirname(__file__), '..')
  15. if _check(name):
  16.     print 'Running uninstalled invest, modifying PYTHONPATH'
  17.     sys.path.insert(0, abspath(name))
  18. else:
  19.     sys.path.insert(0, abspath("/usr/lib/python2.6/site-packages/"))
  20.  
  21. # Now the path is set, import our applet
  22. import invest, invest.applet, invest.defs
  23.  
  24. # Prepare i18n
  25. import gettext, locale
  26. gettext.bindtextdomain(invest.defs.GETTEXT_PACKAGE, invest.defs.GNOMELOCALEDIR)
  27. gettext.textdomain(invest.defs.GETTEXT_PACKAGE)
  28. locale.bindtextdomain(invest.defs.GETTEXT_PACKAGE, invest.defs.GNOMELOCALEDIR)
  29. locale.textdomain(invest.defs.GETTEXT_PACKAGE)
  30.  
  31. from gettext import gettext as _
  32.  
  33. debugging = False
  34.  
  35. def applet_factory(applet, iid):
  36.     if invest.DEBUGGING:
  37.         print 'Starting invest instance:', applet, iid
  38.     invest.applet.InvestApplet(applet)
  39.     return True
  40.  
  41. # Return a standalone window that holds the applet
  42. def build_window():
  43.     app = gtk.Window(gtk.WINDOW_TOPLEVEL)
  44.     app.set_title(_("Invest Applet"))
  45.     app.connect("destroy", gtk.main_quit)
  46.     app.set_property('resizable', False)
  47.     
  48.     applet = gnomeapplet.Applet()
  49.     applet_factory(applet, None)
  50.     applet.reparent(app)
  51.         
  52.     app.show_all()
  53.     
  54.     return app
  55.         
  56.         
  57. def usage():
  58.     print """=== Invest applet: Usage
  59. $ invest-applet [OPTIONS]
  60.  
  61. OPTIONS:
  62.     -h, --help            Print this help notice.
  63.     -d, --debug            Enable debug output (default=off).
  64.     -w, --window        Launch the applet in a standalone window for test purposes (default=no).
  65.     """
  66.     sys.exit()
  67.     
  68. if __name__ == "__main__":    
  69.     standalone = False
  70.     
  71.     try:
  72.         opts, args = getopt.getopt(sys.argv[1:], "hdw", ["help", "debug", "window"])
  73.     except getopt.GetoptError:
  74.         # Unknown args were passed, we fallback to bahave as if
  75.         # no options were passed
  76.         opts = []
  77.         args = sys.argv[1:]
  78.     
  79.     for o, a in opts:
  80.         if o in ("-h", "--help"):
  81.             usage()
  82.         elif o in ("-d", "--debug"):
  83.             invest.DEBUGGING = True
  84.             print "Debugging enabled"
  85.         elif o in ("-w", "--window"):
  86.             standalone = True
  87.             
  88.     if standalone:
  89.         import gnome
  90.         gnome.init(invest.defs.PACKAGE, invest.defs.VERSION)
  91.         build_window()
  92.         gtk.main()
  93.     else:
  94.         gnomeapplet.bonobo_factory(
  95.             "OAFIID:Invest_Applet_Factory",
  96.             gnomeapplet.Applet.__gtype__,
  97.             invest.defs.PACKAGE,
  98.             invest.defs.VERSION,
  99.             applet_factory)
  100.